
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  pool.tablename;
/**
 * @author abc Dictionary
 * */

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;
import utility.MessageGenerator;
import dbmanager.*;


public class Dictionary extends SubPool
{
	
	private Vector<Object> AbrevationVector =  new Vector<Object>();
	public Hashtable<Object,Object> DictionaryMap = new Hashtable<Object,Object>();	
	
	private Vector<Object> NewDictionaryVector = new Vector<Object>();/** stores new hashtables for Update.*/
	private Vector<Object> OldDictionaryVector = new Vector<Object>();/** stores old hashtables for Update.*/
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	
	//private ResultSet rs;
	//private GetIdName gin;
	//private DictionaryDetails dd; 
	//StringBuffer sbrDTB = new StringBuffer();
	//private String msg;//request,
	//private Hashtable<Object, Object> ErrorMap = new Hashtable<Object, Object>();
	//private String tableName = "Dictionary";
	
	PoolLogger pl;
	
	/**Default constructor of Dictionary class*/
	
	/**
	 * Dictionary() takes following parameters: 
	 * @param username it is mobile number given to the all user.
	 * @param message is message provided by the users. 
	 * @param sqlDB it is database object.
	 * */
	public Dictionary(String username, String message)
	{
		//super(username,message,sqlDB);
		this.username=username;
		System.out.println("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.info("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.debug("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.warn("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.fatal("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.error("pool::Dictionary::The message in the Dictionary is : "+message);
		pl.trace("pool::Dictionary::The message in the Dictionary is : "+message);
	}
	
	public Dictionary()
	{
		gin = new GetIdName();
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
		
		//DictionaryDetails dd=new DictionaryDetails(sqlDB);
	}

	
	/** The getInsert() will insert the properties into the Dictionary table.
	 *  @return sbrDTB StringBuffer which store the insertion message for the logger class.
	 * */
	@SuppressWarnings("unchecked")
	public StringBuffer getInsert()
	{
		System.out.println("pool::Dictionary::getInsert()::");
		pl.info("pool::Dictionary::getInsert()::");
		pl.debug("pool::Dictionary::getInsert()::");
		pl.warn("pool::Dictionary::getInsert()::");
		pl.fatal("pool::Dictionary::getInsert()::");
		pl.error("pool::Dictionary::getInsert()::");
		pl.trace("pool::Dictionary::getInsert()::");
		
		for(int i=0;i<AbrevationVector.size();i++)
		{
			try
			{					
				/*DictionaryDetails ps = (DictionaryDetails)AbrevationVector.get(i);
				ps.tempDictionaryMap.put("userid", username);				
				Hashtable<Object , Object > hasht = new Hashtable<Object, Object>();
				hasht.putAll(ps.tempDictionaryMap);*/
				
				Hashtable<Object , Object > hasht = new Hashtable<Object, Object>();
				hasht = (Hashtable<Object, Object>)AbrevationVector.get(i);				
									
				try
				{
					Hashtable<Object, Object> tempHash = new Hashtable<Object, Object>();
					tempHash.put("userid", username);
					tempHash.put("abrevation",hasht.get("abrevation"));
					ResultSet rsAbbrevation = DBManager.getselect(tempHash, Request);
					
					tempHash.clear();
					tempHash.put("userid", username);
					tempHash.put("msgid",hasht.get("msgid"));
					ResultSet rsMsgId = DBManager.getselect(tempHash, Request);
					
					if(rsAbbrevation.next() == false && rsMsgId.next() == false)
					{
						hasht.put("userid", username);
						int j = DBManager.getInsert(Request,hasht);
						if(j>0)
						{
							sbrDTB.append(" Inserted in Dictionary : "+hasht);
							pl.info(sbrDTB);
							pl.debug(sbrDTB);
							pl.warn(sbrDTB);
							pl.fatal(sbrDTB);
							pl.error(sbrDTB);
							pl.trace(sbrDTB);
							String msgid = hasht.get("msgid").toString();
							//String msgid = ps.tempDictionaryMap.get("msgid").toString();
							try
							{
								boolean FLAG=false;
								while(true)
								{
									ResultSet rs = DBManager.getSelect("select * from dictionary where abrevation= '"+msgid+"' and userid ="+username);
									try
									{
										rs.next();
										msgid =  rs.getString("msgid");
										if(msgid.toLowerCase().equals("system"))
										{
											FLAG = true;
											break;
										}
									}
									catch (Exception e) 
									{
										FLAG = false;
										break;
									}
								}
								if(FLAG == false)
								{
									hasht.put("abrevation", msgid);
									hasht.put("msgid", "system");
									DBManager.getInsert(Request,hasht);
								}
								flagResult = true;
							} 
							catch (Exception e) 
							{
								e.printStackTrace();
							}
						}
						else
						{	
							sbrDTB.append(" pool::Dictionary::getInsert():: Sorry, No Proper data");
							pl.info(sbrDTB);
							pl.debug(sbrDTB);
							pl.warn(sbrDTB);
							pl.fatal(sbrDTB);
							pl.error(sbrDTB);
							pl.trace(sbrDTB);
							flagResult = false;
						}
					}
					else
					{
						sbrDTB.append(" pool::Dictionary::getInsert():: " + hasht.get("Abrevation") + " Already present into the table.");
						pl.info(sbrDTB);
						pl.debug(sbrDTB);
						pl.warn(sbrDTB);
						pl.fatal(sbrDTB);
						pl.error(sbrDTB);
						pl.trace(sbrDTB);
						flagResult = false;
					}
				}
				catch(Exception e)
				{
					System.out.println(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.info(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.debug(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.warn(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.fatal(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.error(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					pl.trace(" pool::Dictionary::getInsert()::  Exception since wrong format was given");
					sbrDTB.append(" pool::Dictionary::getInsert()::  Please refer the manual............");
					pl.info(sbrDTB);
					pl.debug(sbrDTB);
					pl.warn(sbrDTB);
					pl.fatal(sbrDTB);
					pl.error(sbrDTB);
					pl.trace(sbrDTB);
					//e.printStackTrace();
				}		
			}
			catch(Exception e)
			{
				System.out.println("Exception is........");
				e.printStackTrace();
				pl.info(e.getMessage());
				pl.debug(e.getMessage());
				pl.warn(e.getMessage());
				pl.fatal(e.getMessage());
				pl.error(e.getMessage());
				pl.trace(e.getMessage());
			}
			
		}
		return sbrDTB;
	}
	
		
	/** The getUpdate() will Update the properties into the Dictionary table.
	 *  @return sbrDTB StringBuffer which store the updation message for the logger class.
	 * */	
	
	@SuppressWarnings("unchecked")
	public StringBuffer getUpdate()
	{	
		 for(int i = 0; i < NewDictionaryVector.size();i++ )
		 {		
			Hashtable<Object,Object> oldDictionaryMap = (Hashtable<Object,Object>)OldDictionaryVector.get(i);
			Hashtable<Object,Object> newDictionaryMap = (Hashtable<Object,Object>)NewDictionaryVector.get(i);
				
			String newDic = "";
			newDictionaryMap.put("userid",username);
			String oldDic = "";
			oldDictionaryMap.put("userid",username);	
			if(oldDictionaryMap.containsKey("msgid"))
			{
				oldDic = oldDictionaryMap.get("msgid").toString();
			}
			else if(oldDictionaryMap.containsKey("abrevation"))
			{
				oldDic = oldDictionaryMap.get("abrevation").toString();	
			}
			
			if(newDictionaryMap.containsKey("msgid"))
			{
				newDic = newDictionaryMap.get("msgid").toString();
			}
			else if(newDictionaryMap.containsKey("abrevation"))
			{
				newDic = newDictionaryMap.get("abrevation").toString();
			}
			
			try
			{
				if(!oldDic.equals("") && !newDic.equals(""))
				{
					ResultSet rsNewDic = DBManager.getselect(newDictionaryMap, Request); // It will returns the specific row from the database for the new dictionary word. 
					ResultSet rsOldDic = DBManager.getselect(oldDictionaryMap, Request); // It will returns the specific row from the database for the old dictionary word.
					if(rsOldDic.next() == true) // Old word must be present into the databse for the specific user.
					{
						if(rsNewDic.next()== false) // New word must not be present into the database for the specific user.
						{
							int j = DBManager.getUpdate(Request,newDictionaryMap,oldDictionaryMap);
							if(j>0)
						 	{
								 System.out.println("pool::Dictionary::getUpadte():: Updated Success fully" + oldDictionaryMap + " with " + newDictionaryMap);
				   				 sbrDTB.append(" Updated Success fully in Dictionary : &" + oldDictionaryMap + " with " + newDictionaryMap);
				   				 pl.info(sbrDTB);
				   				 pl.debug(sbrDTB);
				   				 pl.warn(sbrDTB);
				   				 pl.fatal(sbrDTB);
				   				 pl.error(sbrDTB);
				   				 pl.trace(sbrDTB);
				   				 
				   				 if(oldDictionaryMap.containsKey("msgid") == true && newDictionaryMap.containsKey("msgid") == true )
				   				 {
					   				 String oldMsgid = oldDictionaryMap.get("msgid").toString();//old
					   				 String newMsgid = newDictionaryMap.get("msgid").toString();//new
				   					 boolean FLAG=false;
				   					 while(true)
				   					 {
				   						 Hashtable<Object, Object> sysDictionaryMap = DBManager.getSelect("select * from dictionary where abrevation= '"+oldMsgid+"' and userid ='"+username+"'",1);
				   						 try
				   						 {			   							 
				   							 String sysMsgid=sysDictionaryMap.get("msgid").toString();
				   							 if(sysMsgid.toLowerCase().equals("system"))
				   							 {
				   								 FLAG = true;
				   								 newDictionaryMap.put("abrevation", newMsgid);
						   						 newDictionaryMap.put("msgid", "system");
						   						DBManager.getUpdate(Request, newDictionaryMap, sysDictionaryMap);
				   								 break;
				   							 }
				   						 }
				   						 catch (Exception e) 
				   						 {
				   							 FLAG = false;
				   							 break;
				   						 }
				   					 }
				   					 if(FLAG == false)
				   					 {
				   						newDictionaryMap.put("abrevation", newMsgid);
				   						newDictionaryMap.put("msgid", "system");
				   						DBManager.getInsert(Request,newDictionaryMap);				   						
				   					 }		
				   				 }
				   				flagResult = true;
				   				
				   				if(flagResult == true)
									continue;
								else
									break;
						 	 }
				   			 else
				   			 {	
				   				 System.out.println(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
				   				 sbrDTB.append(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
				   				 pl.info(sbrDTB);
				   				 pl.debug(sbrDTB);
				   				 pl.warn(sbrDTB);
				   				 pl.fatal(sbrDTB);
				   				 pl.error(sbrDTB);
				   				 pl.trace(sbrDTB);
				   				flagResult = false; 
				   			 }							
						}
						else
						{
							 System.out.println(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
							 sbrDTB.append(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
							 pl.info(sbrDTB);
			   				 pl.debug(sbrDTB);
			   				 pl.warn(sbrDTB);
			   				 pl.fatal(sbrDTB);
			   				 pl.error(sbrDTB);
			   				 pl.trace(sbrDTB);
							 flagResult = false; 
						}
					}
					else
					{
						 System.out.println(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
						 sbrDTB.append(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
						 pl.info(sbrDTB);
		   				 pl.debug(sbrDTB);
		   				 pl.warn(sbrDTB);
		   				 pl.fatal(sbrDTB);
		   				 pl.error(sbrDTB);
		   				 pl.trace(sbrDTB);
						 flagResult = false; 
					}
				}
				else
				{	
					System.out.println(" pool::Dictionary::getUpadte():: Enter Proper message with values ");
					 sbrDTB.append(" pool::Dictionary::getUpadte():: Enter proper message values ");
					 pl.info(sbrDTB);
	   				 pl.debug(sbrDTB);
	   				 pl.warn(sbrDTB);
	   				 pl.fatal(sbrDTB);
	   				 pl.error(sbrDTB);
	   				 pl.trace(sbrDTB);
					 flagResult = false; 
				}
			} 
			catch (SQLException e) 
			{		
				e.printStackTrace();
			}
		}
		return sbrDTB;			
	}
	
	
			
	@SuppressWarnings("unchecked")
	public StringBuffer getView() 
	{

		StringBuffer sbrProperty=new StringBuffer();
		Hashtable<Object, Object> Dictionaryhash = new Hashtable<Object, Object>();
		MessageGenerator msg=new MessageGenerator();
		
		Dictionaryhash.putAll(ViewHashtable);
		
		Enumeration< Object> enum1 = Dictionaryhash.keys();
		if(enum1.hasMoreElements()==false)
		{
			sbrProperty.append("Enter condition to view the properties");
			pl.info(sbrProperty);
				 pl.debug(sbrProperty);
				 pl.warn(sbrProperty);
				 pl.fatal(sbrProperty);
				 pl.error(sbrProperty);
				 pl.trace(sbrProperty);
			return sbrProperty;
		}
		
		Vector<Object> VRate  = new Vector<Object>(); 
		
		VRate.addAll(DBManager.getSelectVector(Dictionaryhash, Request));
		if(VRate.isEmpty())
		{
			sbrProperty.append("Record not available");
			pl.info(sbrProperty);
			 pl.debug(sbrProperty);
			 pl.warn(sbrProperty);
			 pl.fatal(sbrProperty);
			 pl.error(sbrProperty);
			 pl.trace(sbrProperty);
			return sbrProperty;
		}
		String RateProperties="";
		for(int j=0;j<VRate.size();j++)
		{
			String RateProperty="";
			Hashtable<Object, Object> TdplObj=new Hashtable<Object, Object>();
			TdplObj=(Hashtable<Object, Object>) VRate.get(j);
			
			RateProperty=msg.convertToMessage(Request, process, TdplObj);
			RateProperties=RateProperties+RateProperty;
			int k=j+1;
			System.out.println("Request is     "+RateProperties);
			sbrProperty.append("    Property "+k+ " : ");
			pl.info("    Property "+k+ " : ");
			 pl.debug("    Property "+k+ " : ");
			 pl.warn("    Property "+k+ " : ");
			 pl.fatal("    Property "+k+ " : ");
			 pl.error("    Property "+k+ " : ");
			 pl.trace("    Property "+k+ " : ");
			sbrProperty.append(RateProperties);
			pl.info(RateProperties);
			 pl.debug(RateProperties);
			 pl.warn(RateProperties);
			 pl.fatal(RateProperties);
			 pl.error(RateProperties);
			 pl.trace(RateProperties);
		}
		return sbrProperty;	
	}

	public Hashtable<Object, Object> getBasicHashtable() {
	
		return null;
	}

	public Hashtable<Object, Object> getDetailHashtabel() {
	
		return null;
	}

	public Hashtable<Object, Object> getHashtabel() {
	
		return null;
	}

	

	public String getType() {

		return null;
	}

	public Vector<Object> getpropertyVector() {
	
		return null;
	}

	public void setHashtable(Hashtable<Object, Object> table) {
		
		
	}

	public void setPropertyVector(Vector<Object> propertydetails) 
	{
		this.AbrevationVector=propertydetails;
		
	}
	
	
	public String getTable() 
	{
		return Request;
	}

	@Override
	public StringBuffer getDelete() {
	
		return null;
	}

	public void setDictionaryMap(Hashtable<Object, Object> oldTransactionHash)
	{
		this.DictionaryMap.putAll(oldTransactionHash);
	}


	public void setNewPropertyVector(Vector<Object> NewPropertyVector)
	{
		this.NewDictionaryVector = NewPropertyVector;	
	}
	
	
	public void setOldPropertyVector(Vector<Object> OldPropertyVector)
	{
		this.OldDictionaryVector = OldPropertyVector;
	}
	
	public void setViewHashtable(Hashtable<Object,Object> hashtable)
	{
		ViewHashtable.putAll(hashtable);
	}
	
	/*public StringBuffer getUpdate()
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		 
		System.out.println("pool :: Dictionary :: getUpdate()::You are in Update");
		ResultSet rs;// /**Creating reference variable of Result set.
		Hashtable<Object,Object> newDictionaryMap = new Hashtable<Object,Object>();
		Hashtable<Object,Object> oldDictionaryMap = new Hashtable<Object,Object>();
		Command cp = new Command(Request,sqlDB);
		SpecialCharacter sp=new SpecialCharacter();
		String spcharMod = null, spcharAdd = null, spCharColon = null;				
		int charFlag = 0;
		int index_firstSpchar = sp.getNextSpChar(0, message.toCharArray());
		
		String spChar = "" + CharAt.CharAT(message, 0);
		
		
		try
		{	// It will fetch the special character for the mod process.
			rs = sqlDB.getSelect("select fieldname,spchar from command where msgtype = '" + Request + "' and process ='" + process + "' order by order1");
			while(rs.next())
			{
				String spchar = rs.getString("spchar");				
				if(spChar.equals(spchar)==true)
				{
					spcharMod = spChar;
					charFlag=1;
					break;
				}					
			}
			if(charFlag==0) // If first special character is not for the mod operation then message will generate.
			{
				sbrDTB.append("pool::Dictionary::getUpadte():: Message is not in proper sequence.");
				System.out.println("pool::Dictionary::getUpadte():: Message is not in proper sequence.");
				return sbrDTB;
			}
			rs.close();
			
			try
			{	// It will fetch the second special character of the Add process.
				rs = sqlDB.getSelect("select spchar from command where msgtype = '" + Request +"' and process = 'add' and spchar is not null order by order1 desc");
				rs.next();
				spCharColon = rs.getString("spchar");								
				rs.close();
			}catch (SQLException e2){ }
			
//			 It will fetch the special character of the Add process.
			rs = sqlDB.getSelect("select fieldname,spchar from command where msgtype = '" + Request + "' and process = 'add' order by order1");
			while(rs.next())
			{
				String spchar = rs.getString("spchar");				
				if(message.contains(rs.getString("spchar")))
				{
					System.out.println("SPCHAR "+ spchar);
					spcharAdd = spchar;
					break;
				}
			}
			rs.close();
			
		}
		catch (Exception e) 
		{
			System.out.println("pool::Dictionary::getUpadte():: Exception while fetching special character");
		}
		
		int i=0, count=0, cnt=0, index=0, index_star = 0,start=0,end=0;
//		 It will get count the special characters for the update() process.
		
		msg=message;
		while(i<msg.length())
		{				
			char ch = CharAt.CharAT(msg,i);
			if(ch == spcharMod.toCharArray()[0])
				count ++;
			i++;
		}
				
		System.out.println("pool::Dictionary::getUpdate():: Special Char : "+spcharMod);
		System.out.println("pool::Dictionary::getUpdate():: Count : "+count);		
		
		
		while(cnt != count)
		{
			System.out.println("Count" + cnt + "\n Message in pool :: Dictionary :: getUpdate():: " + message);
			oldDictionaryMap = new Hashtable<Object,Object>();
			newDictionaryMap = new Hashtable<Object,Object>();
			Hashtable<Object, Object> msgidMap = new Hashtable<Object, Object>();
			
			int index_nextSpchar = Index.indexOf(message, spChar, index_firstSpchar+1);
			
			String stsStr = null; 
			
			if(index_nextSpchar == -1)
			{
				stsStr = message.substring(start);
				//stsStr = cp.getLastProperty(msg, Request, "add");
				index_nextSpchar = end;
			}
			else
			{	
				stsStr = message.substring(index_firstSpchar, index_nextSpchar);
			}
			
			System.out.println("StoS String -->> " + stsStr);
			
			// It will check the "$" and ":" special characters into the string. 
			if(stsStr.contains(spcharAdd)==true && stsStr.contains(spCharColon)==true)
			{	
				//String retStr = null;
				//index_start = Index.indexOf(message, spChar,index); // It will stores the index of "*".
				start = Index.indexOf(message, spcharMod, index);  // It will stores the index of ":".
				end = Index.indexOf(message, spCharColon, index); // It will stores the index of "$".				
				
				
				String oldDic = message.substring(end, sp.getNextSpChar(end, message.toCharArray()));
				System.out.println(" Old Word -- >> " + oldDic);	
					
					oldDictionaryMap = cp.getHashCommand(Request, oldDic,process); //new

					if(oldDictionaryMap.containsKey("ErrorInput"))
					{
						return sbrDTB.append(oldDictionaryMap.toString());
					}
					oldDictionaryMap.put("userid",username);
				//newDictionaryMap.put("msgid", msgid);
				
				
				String newDic = message.substring(start, sp.getNextSpChar(start, message.toCharArray()));
				System.out.println(" New Word -- >> " + newDic);				
				
				newDictionaryMap = cp.getHashCommand(Request, newDic,"add"); //old
				if(newDictionaryMap.containsKey("ErrorInput"))
				{
					return sbrDTB.append(newDictionaryMap.toString());
				}
				newDictionaryMap.put("userid",username);
					
				String abrevation=newDictionaryMap.get("abrevation").toString();					
	
				int intSize=Integer.parseInt(checkSize());
				
				if(abrevation.length()==intSize)
				{
					newDictionaryMap=newDictionaryMap;
				}
				else
				{
					 System.out.println(" pool::Dictionary::getUpadte():: "+newDic + " is not of proper size.");
	   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: "+newDic + " is not of proper size.");
	   				 sbrDTB.append(" pool::Dictionary::getUpadte():: "+newDic + " is not of proper size.");
	   				 newDic="";
				}
				index_star = Index.indexOf(message, spcharAdd, index);
				String msgid = message.substring(index_star, sp.getNextSpChar(index_star, message.toCharArray()));
				msgidMap = cp.getHashCommand(Request,msgid,process);
				
				if(msgidMap.containsKey("msgid") == true)
				{
					msgid = msgidMap.get("msgid").toString();
					System.out.println("Msgid -- >>" + msgid);
					newDictionaryMap.put("msgid", msgid);
					oldDictionaryMap.put("msgid", msgid);
				}
				
				System.out.println(" pool::Dictionary::getUpadte():: New Dictionary word : " + newDictionaryMap + " & Old Dictionary word " + oldDictionaryMap);
				
				try
				{
					if(!oldDic.equals("") && !newDic.equals(""))
					{
						ResultSet rsNewDic = sqlDB.getselect(newDictionaryMap, Request);
						ResultSet rsOldDic = sqlDB.getselect(oldDictionaryMap, Request);
						//System.out.println(rsNewDic.next() + "    " + rsOldDic.next());
						if(rsOldDic.next() == true)
						{
							if(rsNewDic.next()== false)
							{
								int j = sqlDB.getUpdate(Request,newDictionaryMap,oldDictionaryMap);
								if(j>0)
				   			 	{
									 System.out.println("pool::Dictionary::getUpadte():: Updated Success fully" + oldDictionaryMap + " with " + newDictionaryMap);
					   				 sbrDTB.append(" Updated Success fully in Dictionary : &" + oldDictionaryMap + " with " + newDictionaryMap);
					   				 sqlDB.pLog.Logger.append("& Updated in Dictionary : "+newDictionaryMap);
					   				
					   				 if(oldDictionaryMap.containsKey("msgid") == true && newDictionaryMap.containsKey("msgid") == true )
					   				 {
						   				 String oldMsgid = oldDictionaryMap.get("msgid").toString();//old
						   				 String newMsgid = newDictionaryMap.get("msgid").toString();//new
					   					 boolean FLAG=false;
					   					 while(true)
					   					 {
					   						 Hashtable<Object, Object> sysDictionaryMap = sqlDB.getSelect("select * from dictionary where abrevation= '"+oldMsgid+"' and userid ='"+username+"'",1);
					   						 try
					   						 {			   							 
					   							 //String abrevation =  sysDictionaryMap.get("abrevation").toString();
					   							 String sysMsgid=sysDictionaryMap.get("msgid").toString();
					   							 if(sysMsgid.toLowerCase().equals("system"))
					   							 {
					   								 FLAG = true;
					   								 newDictionaryMap.put("abrevation", newMsgid);
							   						 newDictionaryMap.put("msgid", "system");
					   								 sqlDB.getUpdate(Request, newDictionaryMap, sysDictionaryMap);
					   								 break;
					   							 }
					   						 }
					   						 catch (Exception e) 
					   						 {
					   							 FLAG = false;
					   							 break;
					   						 }
					   					 }
					   					 if(FLAG == false)
					   					 {
					   						newDictionaryMap.put("abrevation", newMsgid);
					   						newDictionaryMap.put("msgid", "system");
					   						sqlDB.getInsert(Request,newDictionaryMap);
					   						//break;
					   					 }		
					   				 }
				   			 	 }
					   			 else
					   			 {	
					   				 System.out.println(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   				 sbrDTB.append(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   			 }							
							}
							else
							{
								 System.out.println(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
				   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
				   				 sbrDTB.append(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
							}
						}
						else
						{
							 System.out.println(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
			   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
			   				 sbrDTB.append(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
						}
					}
					else
		   			{	
						 System.out.println(" pool::Dictionary::getUpadte():: Enter Proper message with values ");
		   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: Enter proper message values ");
		   				 sbrDTB.append(" pool::Dictionary::getUpadte():: Enter proper message values ");
		   			}	
					
					index_firstSpchar = Index.indexOf(message, spChar, end);
					index = index_firstSpchar;
				
					cnt++;
				}
				catch(Exception e)
				{
					System.out.println("pool::Dictionary::getUpadte():: Exception ");
					e.printStackTrace();
				}
			}
			else
			{
				try
				{	
					
					start = Index.indexOf(message, spcharAdd,index+1); // It will stores the index of "*" or ":".
					end = Index.indexOf(message, spcharMod, index+1); // It will stores the index of "$" or ",".							
					
					String newDic = message.substring(0,start);
					System.out.println(" New Word -- >> " + newDic);				
					newDictionaryMap = cp.getHashCommand(Request, newDic,process); //new
					if(newDictionaryMap.containsKey("ErrorInput"))
				 	{
						return new StringBuffer(newDictionaryMap.toString());
					}
					newDictionaryMap.put("userid",username);
					
					
					String oldDic = message.substring(start);
					System.out.println(" Old Word -- >> " + oldDic);
					oldDictionaryMap = cp.getHashCommand(Request, oldDic,"add"); //old
					if(oldDictionaryMap.containsKey("ErrorInput"))
				 	{
						return new StringBuffer(oldDictionaryMap.toString());
					}
					oldDictionaryMap.put("userid",username);	
					
					System.out.println(" New Dictionary word : " + newDictionaryMap + " & Old Dictionary word " + oldDictionaryMap);
					
					if(oldDictionaryMap.containsKey("msgid"))
					{
						oldDic = oldDictionaryMap.get("msgid").toString();
					}
					else if(oldDictionaryMap.containsKey("abrevation"))
					{
						oldDic = oldDictionaryMap.get("abrevation").toString();	
					}
					
					if(newDictionaryMap.containsKey("msgid"))
					{
						newDic = newDictionaryMap.get("msgid").toString();
					}
					else if(newDictionaryMap.containsKey("abrevation"))
					{
						newDic = newDictionaryMap.get("abrevation").toString();
					}
					
					if(!oldDic.equals("") && !newDic.equals(""))
					{
						ResultSet rsNewDic = sqlDB.getselect(newDictionaryMap, Request); // It will returns the specific row from the database for the new dictionary word. 
						ResultSet rsOldDic = sqlDB.getselect(oldDictionaryMap, Request); // It will returns the specific row from the database for the old dictionary word.
						//System.out.println(rsNewDic.next() + "    " + rsOldDic.next());
						if(rsOldDic.next() == true) // Old word must be present into the databse for the specific user.
						{
							if(rsNewDic.next()== false) // New word must not be present into the database for the specific user.
							{
								int j = sqlDB.getUpdate(Request,newDictionaryMap,oldDictionaryMap);
								if(j>0)
				   			 	{
									 System.out.println("pool::Dictionary::getUpadte():: Updated Success fully" + oldDictionaryMap + " with " + newDictionaryMap);
					   				 sbrDTB.append(" Updated Success fully in Dictionary : &" + oldDictionaryMap + " with " + newDictionaryMap);
					   				 sqlDB.pLog.Logger.append("& Updated in Dictionary : "+newDictionaryMap);
					   				
					   				 if(oldDictionaryMap.containsKey("msgid") == true && newDictionaryMap.containsKey("msgid") == true )
					   				 {
						   				 String oldMsgid = oldDictionaryMap.get("msgid").toString();//old
						   				 String newMsgid = newDictionaryMap.get("msgid").toString();//new
					   					 boolean FLAG=false;
					   					 while(true)
					   					 {
					   						 Hashtable<Object, Object> sysDictionaryMap = sqlDB.getSelect("select * from dictionary where abrevation= '"+oldMsgid+"' and userid ='"+username+"'",1);
					   						 try
					   						 {			   							 
					   							 //String abrevation =  sysDictionaryMap.get("abrevation").toString();
					   							 String sysMsgid=sysDictionaryMap.get("msgid").toString();
					   							 if(sysMsgid.toLowerCase().equals("system"))
					   							 {
					   								 FLAG = true;
					   								 newDictionaryMap.put("abrevation", newMsgid);
							   						 newDictionaryMap.put("msgid", "system");
					   								 sqlDB.getUpdate(Request, newDictionaryMap, sysDictionaryMap);
					   								 break;
					   							 }
					   						 }
					   						 catch (Exception e) 
					   						 {
					   							 FLAG = false;
					   							 break;
					   						 }
					   					 }
					   					 if(FLAG == false)
					   					 {
					   						newDictionaryMap.put("abrevation", newMsgid);
					   						newDictionaryMap.put("msgid", "system");
					   						sqlDB.getInsert(Request,newDictionaryMap);
					   						break;
					   					 }		
					   				 }
				   			 	 }
					   			 else
					   			 {	
					   				 System.out.println(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   				 sbrDTB.append(" pool::Dictionary::getUpadte():: Unable to Update into Dictionary : ");
					   			 }							
							}
							else
							{
								 System.out.println(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
				   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
				   				 sbrDTB.append(" pool::Dictionary::getUpadte():: "+newDic + " is already exist.");
							}
						}
						else
						{
							 System.out.println(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
			   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
			   				 sbrDTB.append(" pool::Dictionary::getUpadte():: "+ oldDic + " does not exist in dictionary.");
						}
					}
					else
		   			{	
						 System.out.println(" pool::Dictionary::getUpadte():: Enter Proper message with values ");
		   				 sqlDB.pLog.Logger.append("\n pool::Dictionary::getUpadte():: Enter proper message values ");
		   				 sbrDTB.append(" pool::Dictionary::getUpadte():: Enter proper message values ");
		   			}	
					//index = Index.indexOf(message, spcharAdd, end);;
	   				cnt++;
				}
				catch(Exception e)
				{
					System.out.println("pool::Dictionary::getUpadte():: Exception ");
					e.printStackTrace();
				}
			}	
		}
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Dictionary","getUpdate",t.duration());
		
		return sbrDTB;
	}
	
<<<<<<< .mine
	@SuppressWarnings("unchecked")
	public StringBuffer getView() 
	{

		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		StringBuffer sbrProperty=new StringBuffer();
		Hashtable<Object, Object> Dictionaryhash = new Hashtable<Object, Object>();
		MessageGenerator msg=new MessageGenerator(sqlDB);
		
		Command cp = new Command(tableName, sqlDB);
		Dictionaryhash = cp.getHashCommand(tableName,message,process); 
		if(Dictionaryhash.containsKey("ErrorInput"))
		{
			sbrProperty.append(Dictionaryhash.get("ErrorInput"));
			return sbrProperty;
		}
		
		
		//Dictionaryhash.putAll(hashMap);
		//Dictionaryhash=gin.convertMasterId(Dictionaryhash, Request, process);
		Enumeration< Object> enum1 = Dictionaryhash.keys();
		if(enum1.hasMoreElements()==false)
		{
				sbrProperty.append("Enter condition to view the properties");
				return sbrProperty;
		}
		
		Vector<Object> VRate  = new Vector<Object>(); 
		
		VRate.addAll(sqlDB.getSelectVector(Dictionaryhash, Request));
		if(VRate.isEmpty())
		{
			sbrProperty.append("Record not available");
			return sbrProperty;
		}
		String RateProperties="";
		for(int j=0;j<VRate.size();j++)
		{
			String RateProperty="";
			Hashtable<Object, Object> TdplObj=new Hashtable<Object, Object>();
			TdplObj=(Hashtable<Object, Object>) VRate.get(j);
			
			RateProperty=msg.convertToMessage(Request, process, TdplObj);
			RateProperties=RateProperties+RateProperty;
			int k=j+1;
			System.out.println("Request is     "+RateProperties);
			sbrProperty.append("    Property "+k+ " : ");
			sbrProperty.append(RateProperties);
		}
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Dictionary","getView",t.duration());
			return sbrProperty;
	
	
	}

	

	public Hashtable<Object, Object> getBasicHashtable() {
	
		return null;
	}

	public Hashtable<Object, Object> getDetailHashtabel() {
	
		return null;
	}

	public Hashtable<Object, Object> getHashtabel() {
	
		return null;
	}

=======
>>>>>>> .r1627
	public String getProceess() {
	
		return null;
	}
	
	*/

	/*public void setOldProperty(Hashtable<Object, Object> oldTransactionHash)
	{
		this.oldDictionaryMap.putAll(oldTransactionHash);
		
	}

	public void setNewProperty(Hashtable<Object, Object> newTransactionHash) 
	{
		this.newDictionaryMap.putAll(newTransactionHash); 
		
	}*/

}
		